import React, { useEffect, useState } from 'react'
import { AppstoreOutlined, MailOutlined, SettingOutlined, LeftOutlined,UnorderedListOutlined } from '@ant-design/icons';
import { Menu } from 'antd';
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
export default function StoreItem() {
  const navigate = useNavigate()
  const location = useLocation()
  const items = [
    {
      key: "return",
      icon: <LeftOutlined />
    },
    {
      label: '商品管理',
      key: 'goods',
      icon: <AppstoreOutlined />,
    },
    {
      label:'订单管理',
      key:'order',
      icon:<UnorderedListOutlined />,
    },
    {
      label: '门店信息',
      key: 'info',
      icon: <MailOutlined />
    },
  ];
  const [current, setCurrent] = useState(location.pathname.split('/')[3]);
  const onClick = (e) => {
    const rid = location.pathname.split('/')[2];
    setCurrent(e.key);
    if (e.key === 'return') {
      navigate(`/store/manage`,{replace:true})
    } else {
      navigate(`/store/${rid}/${e.key}`, { replace: true, state: rid })
    }

  };
  return (
    <>
      <Menu onClick={onClick} selectedKeys={[current]} mode="horizontal" items={items} />
      <Outlet></Outlet>
    </>
  )
}
